package com.liangzhong.model.playerCenter.vo
{
	import com.common.utils.Debug;
	import com.global.GlobalDef;
	import com.liangzhong.constants.ClubConst;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.AttributeVo;
	import com.liangzhong.model.goods.vo.FootwearVo;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.goods.vo.PlayerStarVo;
	import com.liangzhong.model.playerCenter.PlayerCenterDataConstant;
	import com.liangzhong.model.type.GoodsType;
	
	import flash.utils.ByteArray;

	/**
	 * 球员信息vo 基类
	 * 其他各个模块球员信息继承此类
	 * @author lake
	 * 
	 */	
	public class PlayerVo
	{
		/**
		 * 球员id
		 */
		public var playerid  :int;
		/**
		 *球星id 
		 */
		public var starid  :int;
		
		
		/**
		 *是否可用 1可用 2不可用 
		 */
		public var ifuse :int;
		/**
		 * 是否自身球员：
		 * 1.	是
		 * 2.	不是
		 */
		public var self:int;
		/**
		 *  成色：
		 * 1.	灰
		 * 2.	绿
		 * 3.	蓝
		 * 4.	紫
		 * 5.	橙
		 * 6.	红
		 * 7.	 黑
		 *  		 
		 * */
		public var color :int;
		/**
		 *level 等级 
		 */
		public var level :int;
		/**
		 *下一级升级经验 
		 */
		public var nextexp:int;
		/**
		 *经验 
		 */
		public var exp :int;
		/**
		 *体力 
		 */
		public var physical  :int;
		/**
		 *体力上限 
		 */
		public var maxphysical :int;
		/**
		 *状态：1健康， 2受伤 
		 */
		public var status :int;
		/**
		 *薪水 
		 */
		public var salary :int;
		/**
		 *属性槽1 
		 */
		public var attr1  :int;
		/**
		 *属性槽1 锁定 
		 * 装备是否加锁
		 * 1.	加锁 2. 未加锁
		 */
		public var attr1lock:int;
		/**
		 *属性槽2 
		 */
		public var attr2  :int;
		/**
		 * 属性槽2 锁定
		 *  * 装备是否加锁
		 * 1.	加锁 2. 未加锁
		 */
		public var attr2lock:int;
		/**
		 *装备槽1 
		 */
		public var equip1 :int;
		/**
		 * 装备槽1 锁定
		 *  * 装备是否加锁
		 * 1.	加锁 2. 未加锁
		 */
		public var equip1lock:int;
		/**
		 *装备槽2 
		 */
		public var equip2 :int;
		/**
		 * 装备槽2 锁定
		 *  * 装备是否加锁
		 * 1.	加锁 2. 未加锁
		 */
		public var equip2lock:int;
		/**
		 *球员号 
		 */
		public var number :int;
		/**
		 *球员位置：
		 * 1.	GK
		 * 2.	DF后卫
		 * 3.	MF中场
		 * 4.	FW前锋
		 */
		public var place :int;
		/**
		 *球员位置 
		 */
		public var place_String:String;
		/**
		 *综合能力 
		 */
		public var  ability:int;
		/**
		 *进攻 
		 */
		public var attack :int;
		/**
		 * 进攻加成
		 */
		public var attackAdd:int;
		/**
		 *进攻概率 
		 */
		public var attprob :int;
		/**
		 *防守 
		 */
		public var defence :int;
		/**
		 *防守加成 
		 */
		public var defenceAdd:int;
		/**
		 *防守概率 
		 */
		public var defprob :int;
		/**
		 *抢断 
		 */
		public var steal  :int;
		/**
		 *抢断加成 
		 */
		public var stealAdd:int;
		/**
		 *抢断概率 
		 */
		public var steprob :int;
		/**
		 *力量 
		 */
		public var power :int;
		/**
		 *力量加成 
		 */
		public var powerAdd:int;
		
		/**
		 *力量概率 
		 */
		public var powprob :int;
		
		/**
		 *速度 
		 */
		public var speed :int;
		/**
		 *速度加成 
		 */
		public var speedAdd:int;
		/**
		 *速度概率 
		 */
		public var speprob :int;
		/**
		 *控球 
		 */
		public var control :int;
		/**
		 *控球加成 
		 */
		public var controlAdd:int;
		/**
		 *控球概率 
		 */
		public var conprob :int;
		/**
		 *专注 
		 */
		public var concent :int;
		/**
		 *潜力 
		 */
		public var potent :int;
		
		
		
		/************球星表数据***/
		/**
		 *球星名字 
		 */		
		public var pname 			:String;
		/**
		 *大图片相对地址 
		 */		
		public var bigheader 		:String;
		/**
		 *所在洲ID：
		 1.	Austrlia
		 2.	Asia
		 3.	NorthAmerica
		 4.	Africa
		 5.	Europe
		 6.	SouthAmerica
		 */		
		public var land				:int;
		/**
		 *擅长位置 
		 */		
		public var adept 			:String;
		/**
		 *球员特点 
		 */		
		public var point 			:String;
		/**
		 *物品头像地址 
		 */		
		public var url			:String;
		/**
		 *头像 相对地址 
		 */		
		public var header 		:String;
		private var _starVo:PlayerStarVo;
		
		/**
		 *阵容
		 * 第一阵容为1 其他阵容或者不在场上为0； 
		 */
		public var formation:int;
		
		
		////////好友信息中使用//////////////////
		/**
		 * x
		 */
		public var flasx:int;
		/**
		 * y
		 */
		public var flasy:int;
		
		public function PlayerVo()
		{
		}
		/**
		 *解析数据  
		 * @param obj
		 * 
		 */
		public function analysisData(obj:*):void
		{
			for(var str:String in obj)
			{
				if(this.hasOwnProperty(str))
				{
					this[str] = obj[str];
				}else
				{
//					Debug.echo("PlayerVo中没有" + str + "属性");
				}
			}
			turnPlace();
			updataValue();
			colorTosalary();
//			starVo = AppData.getInstance().goodsManager.getStarById(starid) as PlayerStarVo;
//			if(pname != null && pname != "")
//			{
//				name = pname;
//			}
		}

		/**
		 *获取一个球员 
		 * 
		 */
		public function addPlayer($startId:int):void
		{
			_starVo = AppData.getInstance().goodsManager.getStarById($startId) as PlayerStarVo;	
			if(_starVo == null)return;
			attack = _starVo.attack;
			place = _starVo.place;
			defence = _starVo.defence;
			steal = _starVo.steal;
			power = _starVo.power;
			speed = _starVo.speed;
			control = _starVo.control;
			concent = _starVo.concent;
			potent = _starVo.potent;
			color = _starVo.color;
			self = 2;
			level = _starVo.level;
			
//			exp = _starVo.explorelevel
			
			physical = _starVo.physical;
			maxphysical = physical;//_starVo.maxphysical;
			status = 1;
			salary = 10000//_starVo.salary;工资
			nextexp = 100;
			attr1 = 0;
			attr2 = 0;
			equip1 = 0;
			equip2 = 0;
			
			
			turnPlace();
			updataValue();
			colorTosalary();
		}
		/**
		 *球星数据 
		 */
		public function get starVo():PlayerStarVo
		{
			if(_starVo == null)
			{
				if(self == 1)
				{
					_starVo = new PlayerStarVo();
					_starVo.type = GoodsType.PLAYERCARD;
					_starVo.name = AppData.getInstance().clubDatamanager.clubInfo.uname;
					_starVo.pname = AppData.getInstance().clubDatamanager.clubInfo.uname;
					_starVo.bigheader = AppData.getInstance().clubDatamanager.clubInfo.header;
					_starVo.place = place;
					_starVo.url = GlobalDef.Web_Res_Url + "star/self.png";//默认头像
					_starVo.bigheader = GlobalDef.Web_Res_Url + "star/bigself.png";
					_starVo.level 		= level;
					_starVo.self		= self;
				}else
				{
					_starVo = AppData.getInstance().goodsManager.getStarById(starid) as PlayerStarVo;	
					if(_starVo == null)
					{
						_starVo = new PlayerStarVo();
						_starVo.type = GoodsType.PLAYERCARD;
						_starVo.name = pname;
						_starVo.pname = pname;
						_starVo.place = place;
						_starVo.url = GlobalDef.Web_Res_Url + "star/default.png";//默认头像
						_starVo.bigheader = GlobalDef.Web_Res_Url + "star/bdefault.png";
						_starVo.level 		= level;
					}
				}
			}
			if(self == 1)
			{
				_starVo.ability		= AppData.getInstance().playerCenterDataManager.getSelfInfo().ability;
			}
//			addPlayer(starid);
			return _starVo;
		}
		/**
		 *设置球星数据
		 * 查看他人信息时使用 
		 * 
		 */
		public function setStartVo():void
		{
			if(_starVo== null)return;
			_starVo = new PlayerStarVo();
			starVo.type = GoodsType.PLAYERCARD;
			starVo.place = place;
			starVo.url = GlobalDef.Web_Res_Url + "star/default.png";//默认头像
		}
		/**
		 *更新球员体力 
		 * @param value
		 * 
		 */
		public function updatapphysical(value:int):void
		{
			physical += value;
			if(physical > maxphysical)
				physical = maxphysical;
			if(physical <0)
				physical = 0;
		}

		/**
		 *更新球员基础数据 
		 * @param buffer
		 * 
		 */
		public function updataBaseValue(buffer:ByteArray):Object
		{
			level =  buffer.readShort();;
			nextexp = buffer.readInt();
			exp = 0;
//			salary = buffer.readInt();
			var sala:int = buffer.readInt();//球员薪水
			colorTosalary();//根据成色转换薪水
			ability = buffer.readShort();
			var value:int =  buffer.readShort();
//			var arr:Array = [];
			var obj:Object = {};
			obj.attachAdd = value - attack;
			obj.attach = attack;
			attack = value;
//			if(obj.attachAdd < 0)
//			{
//				trace("");
//			}
			
			value = buffer.readShort();
			obj.defenceAdd = value - defence;
			obj.defence = defence;
//			if(obj.defenceAdd < 0)
//			{
//				trace("");
//			}
			defence = value;
			
			
			value = buffer.readShort();
			obj.stealAdd = value - steal;
			obj.steal = steal;
			steal = value;
//			if(obj.stealAdd < 0)
//			{
//				trace("");
//			}
			
			
			value = buffer.readShort();
			obj.powerAdd = value - power;
			obj.power = power;
			power = value;
//			if(obj.powerAdd < 0)
//			{
//				trace("");
//			}
			
			
			value = buffer.readShort();
			obj.speedAdd = value - speed;
			obj.speed = speed;
			speed = value;
//			if(obj.speedAdd < 0)
//			{
//				trace("");
//			}
			
			
			value = buffer.readShort();
			obj.controlAdd = value - control;
			obj.control = control;
			control = value;
			
//			if(obj.controlAdd < 0)
//			{
//				trace("");
//			}
			return obj;
		}
		/**
		 * @private
		 */
		public function set starVo(value:PlayerStarVo):void
		{
			_starVo = value;
		}
		/**
		 *  
		 * 
		 */
		public function turnPlace():void
		{
//			switch(place)
//			{
//				case PlayerCenterDataConstant.GK_PLACE:
//					place_String = "GK";
//					break;
//				case PlayerCenterDataConstant.DF_PLACE:
//					place_String = "DF";
//					break;
//				case PlayerCenterDataConstant.MF_PLACE:
//					place_String = "MF";
//					break;
//				case PlayerCenterDataConstant.FW_PLACE:
//					place_String = "FW";
//					break;
//				default:
//					place_String = "";
//			}
			place_String = ClubConst.turnPlace(place);
		}

		/**
		 *更换装备 
		 * @param buffer
		 * 
		 */
		public function replaceEquip(buffer:ByteArray):void
		{
			var goodId:int = buffer.readInt();
			var posid:int = buffer.readByte();//1.	位置  2.	位置
			var ntype:int = buffer.readByte();//3.	属性卡2.	鞋袜卡
			var lock:int = buffer.readByte();//装备是否加锁1.	加锁 2. 未加锁

			if(ntype == 3)//属性卡
			{
				if(posid ==1)
				{
					attr1 = goodId;
					attr1lock = lock;
				}else if(posid == 2)
				{
					attr2 = goodId;
					attr2lock = lock;
				}
			}else if(ntype == 2)//鞋袜
			{
				if(posid ==1)
				{
					equip1 = goodId
					equip1lock = lock;
				}else if(posid == 2)
				{
					equip2 = goodId;
					equip2lock = lock;
				}
			}
			updataValue();
		}
		/**
		 *球员升级 
		 * 
		 */
		public function upLv():void
		{
			
			updataValue();
		}
		/**
		 *更新六项属性 
		 * 
		 */
		public function updataValue():void
		{
			var attr1Vo:AttributeVo;//属性1
			var attr2Vo:AttributeVo;//属性2
			var equip1Vo:FootwearVo;//装备1
			var equip2Vo:FootwearVo;//装备2
			if(attr1 > 0)attr1Vo = AppData.getInstance().goodsManager.getAttributeById(attr1) as AttributeVo;
			if(attr2 > 0)attr2Vo = AppData.getInstance().goodsManager.getAttributeById(attr2) as AttributeVo;
			
			if(equip1 > 0)equip1Vo = AppData.getInstance().goodsManager.getFootWearById(equip1) as FootwearVo;
			if(equip2 > 0)equip2Vo = AppData.getInstance().goodsManager.getFootWearById(equip2) as FootwearVo;
			countattackadd(attr1Vo,attr2Vo,equip1Vo,equip2Vo);
			countdefenceAdd(attr1Vo,attr2Vo,equip1Vo,equip2Vo);
			countstealAdd(attr1Vo,attr2Vo,equip1Vo,equip2Vo);
			countpowerAdd(attr1Vo,attr2Vo,equip1Vo,equip2Vo);
			countspeedAdd(attr1Vo,attr2Vo,equip1Vo,equip2Vo);
			countcontrolAdd(attr1Vo,attr2Vo,equip1Vo,equip2Vo);
			
		}
		
		/**
		 *计算进攻加成 
		 * 
		 */
		private function countattackadd(attr1:AttributeVo,attr2:AttributeVo,equip1:FootwearVo,equip2:FootwearVo):void
		{
			attackAdd = 0;
			var per:int;
//			per = status == PlayerCenterDataConstant.PLAYER_STATUS_1?100:50;
			if(attr1 != null)per += attr1.attack//先计算属性加成和状态加成
			if(attr2 != null)per += attr2.attack;
			attackAdd =  Math.floor((attack * per) / 100);
			if(equip1 != null)attackAdd += equip1.attack;//计算装备加成
			if(equip2 != null)attackAdd += equip2.attack;
		}
		/**
		 * 计算防守加成 
		 * @param attr1
		 * @param attr2
		 * @param equip1
		 * @param equip2
		 * 
		 */
		private function countdefenceAdd(attr1:AttributeVo,attr2:AttributeVo,equip1:FootwearVo,equip2:FootwearVo):void
		{
			defenceAdd = 0;
			var per:int;//属性 +状态加成
//			per = status == PlayerCenterDataConstant.PLAYER_STATUS_1?100:50;
			if(attr1 != null)per += attr1.defence//先计算属性加成和状态加成
			if(attr2 != null)per += attr2.defence
			defenceAdd =  Math.floor((defence * per) / 100);
			if(equip1 != null)defenceAdd += equip1.defence;//计算装备加成
			if(equip2 != null)defenceAdd += equip2.defence;
		}
		/**
		 *抢断加成 
		 * @param attr1
		 * @param attr2
		 * @param equip1
		 * @param equip2
		 * 
		 */
		private function countstealAdd(attr1:AttributeVo,attr2:AttributeVo,equip1:FootwearVo,equip2:FootwearVo):void
		{
			stealAdd = 0;
			var per:int;//属性 +状态加成
//			per = status == PlayerCenterDataConstant.PLAYER_STATUS_1?100:50;
			if(attr1 != null)per += attr1.steal;//先计算属性加成和状态加成
			if(attr2 != null)per += attr2.steal;
			stealAdd =  Math.floor((steal * per) / 100);
			if(equip1 != null)stealAdd += equip1.steal;//计算装备加成
			if(equip2 != null)stealAdd += equip2.steal;
		}
		
		/**
		 *力量加成 
		 * @param attr1
		 * @param attr2
		 * @param equip1
		 * @param equip2
		 * 
		 */
		private function countpowerAdd(attr1:AttributeVo,attr2:AttributeVo,equip1:FootwearVo,equip2:FootwearVo):void
		{
			powerAdd = 0;
			var per:int;//属性 +状态加成
//			per = status == PlayerCenterDataConstant.PLAYER_STATUS_1?100:50;
			if(attr1 != null)per += attr1.power;//先计算属性加成和状态加成
			if(attr2 != null)per += attr2.power;
			powerAdd =  Math.floor((power * per) / 100);
			if(equip1 != null)powerAdd += equip1.power;//计算装备加成
			if(equip2 != null)powerAdd += equip2.power;
		}
		/**
		 * 速度加成 
		 * @param attr1
		 * @param attr2
		 * @param equip1
		 * @param equip2
		 * 
		 */
		private function countspeedAdd(attr1:AttributeVo,attr2:AttributeVo,equip1:FootwearVo,equip2:FootwearVo):void
		{
			speedAdd = 0;
			var per:int;//属性 +状态加成
//			per = status == PlayerCenterDataConstant.PLAYER_STATUS_1?100:50;
			if(attr1 != null)per += attr1.speed;//先计算属性加成和状态加成
			if(attr2 != null)per += attr2.speed;
			speedAdd =  Math.floor((speed * per) / 100);
			if(equip1 != null)speedAdd += equip1.speed;//计算装备加成
			if(equip2 != null)speedAdd += equip2.speed;
		}
		/**
		 *控球加成 
		 * @param attr1
		 * @param attr2
		 * @param equip1
		 * @param equip2
		 * 
		 */
		private function countcontrolAdd(attr1:AttributeVo,attr2:AttributeVo,equip1:FootwearVo,equip2:FootwearVo):void
		{
			controlAdd = 0;
			var per:int;//属性 +状态加成
//			per = status == PlayerCenterDataConstant.PLAYER_STATUS_1?100:50;
			if(attr1 != null)per += attr1.control;//先计算属性加成和状态加成
			if(attr2 != null)per += attr2.control;
			controlAdd =  Math.floor((control * per) / 100);
			if(equip1 != null)controlAdd += equip1.control;//计算装备加成
			if(equip2 != null)controlAdd += equip2.control;
		}
		/**
		 *数据复制给球星vo 物品类 
		 * @return 
		 * 
		 */		
		public function copyToStarVo():PlayerStarVo
		{
			var goodsVo :GoodsVo = starVo;
			var startVo :PlayerStarVo;
			if(goodsVo)
			{
				startVo = goodsVo.clone() as PlayerStarVo;
			}
			else
			{
				startVo = new PlayerStarVo();
			}
			startVo.level 		= level;
			startVo.attack 		= attack;
			startVo.defence 	= defence;
			startVo.power 		= power;
			startVo.steal 		= steal;
			startVo.speed 		= speed;
			startVo.control 	= control;
			startVo.color 		= color;
			startVo.playerid 	= playerid;
			startVo.self		= self;
			startVo.place	 	= place;
			startVo.ability 	= ability;
			return startVo;
		}
		/**
		 *恢复到1级属性 
		 */		
		public function toOneLevInfo():void
		{
			var pvo :PlayerStarVo = starVo;
			level 		= 1;
			attack 		= pvo.attack;
			defence 	= pvo.defence;
			power 		= pvo.power;
			steal 		= pvo.steal;
			speed 		= pvo.speed;
			control 	= pvo.control;
			color 		= pvo.color;
		}
		private function colorTosalary():void
		{
			switch(color)
			{
				case 1:
					salary = 10
					break;
				case 2:
					salary = 50;
					break;
				case 3:
					salary = 100 
					break;
				case 4:
					salary = 500;
					break;
				case 5:
					salary = 5000;
					break;
				case 6:
					salary = 20000;
					break;
				case 7:
					salary = 50000;
					break;
				case 8:
					salary = 200000;
					break;
					
					
			}
		}
	}
}